package com.sqf.soft.utils;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResultMap {

    public static Map<String, Object> getObject(Object object) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", SystemConstant.SUCCESS);
        resultMap.put("errMsg", SystemConstant.getCommentByCode(SystemConstant.SUCCESS));
        resultMap.put("data", object);
        return resultMap;
    }

    public static Map<String, Object> getObject(int code) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", code);
        resultMap.put("errMsg", SystemConstant.getCommentByCode(code));
        resultMap.put("data", new JSONObject());
        return resultMap;
    }

    public static Map<String, Object> getPage(int amount, List list) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", SystemConstant.SUCCESS);
        resultMap.put("errMsg", SystemConstant.getCommentByCode(SystemConstant.SUCCESS));

        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("amount", amount);
        dataMap.put("list", JSONArray.fromObject(list));

        resultMap.put("data", dataMap);

        return resultMap;
    }

    public static Map<String, Object> getPage(int code) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", code);
        resultMap.put("errMsg", SystemConstant.getCommentByCode(code));

        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("amount", SystemConstant.NO);
        dataMap.put("list", new JSONArray());

        resultMap.put("data", dataMap);

        return resultMap;
    }

    public static Map<String, Object> getList(List list) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", SystemConstant.SUCCESS);
        resultMap.put("errMsg", SystemConstant.getCommentByCode(SystemConstant.SUCCESS));
        resultMap.put("list", JSONArray.fromObject(list));
        return resultMap;
    }

    public static Map<String, Object> getList(int code) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", code);
        resultMap.put("errMsg", SystemConstant.getCommentByCode(code));
        resultMap.put("list", new ArrayList());
        return resultMap;
    }

    public static Map<String, Object> getTree(JSONArray jsonArray) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", SystemConstant.SUCCESS);
        resultMap.put("errMsg", SystemConstant.getCommentByCode(SystemConstant.SUCCESS));
        resultMap.put("list", jsonArray);
        return resultMap;
    }

    public static Map<String, Object> operate(int code) {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("errCode", code);
        resultMap.put("errMsg", SystemConstant.getCommentByCode(code));
        return resultMap;
    }
}
